import mongoose from 'mongoose'
import config from '../config/index'
mongoose.connect(config.url,{
    useNewUrlParser: true,
    useUnifiedTopology: true
});
let db = mongoose.connection;
db.once('open',() => {
    console.log("连接成功")
})
db.on('error',(err) => {
    console.error(err)
    db.disconnect()
})
db.on('close',() => {
    console.log('已断开连接，请重新连接')
    db.connect(config.url,{
        auto_reconnect:true
    })
})